package com.brspace.qualitycontrol.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brspace.qualitycontrol.entity.Role;
import com.brspace.qualitycontrol.mapper.RoleMapper;
import com.brspace.qualitycontrol.service.RoleService;
import com.brspace.qualitycontrol.utils.EmptyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangT
 * @since 2021-03-23
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Resource
    private RoleMapper roleMapper;
    /**
     * 角色列表
     * @Author: wangt
     * @Date: 2021-04-21 13:55:13
     */
    @Override
    public List<Role> selectRoleListByUserId(String id) {
        return roleMapper.findRoleListByUserId(id);
    }
    /**
     * 添加角色
     * @Author: wangt
     * @Date: 2021-04-21 13:55:42
     */
    @Override
    public void add(Role role) {
        if (EmptyUtil.isEmpty(role.getName()) || EmptyUtil.isEmpty(role.getRoleName())) {
            throw new SecurityException("请检查参数！");
        }
        Role selectOne = baseMapper.selectOne(new QueryWrapper<Role>().eq("role_name", role.getRoleName()).or().eq("name", role.getName()));
        if (EmptyUtil.isNotEmpty(selectOne)) {
            throw new SecurityException("改角色已存在！");
        }
        baseMapper.insert(role);
    }
}
